package org.dna.opdracht3;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TrieTest {

	public static Trie trie;

	@Before
	public void setUp() throws Exception {
		trie = new Trie();
	}

	@After
	public void tearDown() throws Exception {
		trie = null;
	}

	
	@Test
	public void searchTest() {
		trie.search("World");
		assertNull(trie.search("World"));
	}
	
	@Test
	public void insertTest() {
		Data data = new Data(5);
		trie.insert("World", data);
		assertNotNull(trie.search("World"));
	}
	
	@Test
	public void insertTest2() {
		Data data = new Data(5);
		trie.insert("World", data);
		trie.insert("Word", data);
		assertNotNull(trie.search("World"));
		assertNotNull(trie.search("Word"));
	}
	
	@Test
	public void insertTest3() {
		Data data = new Data(5);
		trie.insert("World", data);
		trie.insert("Word", data);
		trie.delete("Word");
		assertNull(trie.search("Word"));
		assertNotNull(trie.search("World"));
	}
	
	@Test
	public void deleteTest() {
		Data data = new Data(5);
		trie.insert("World", data);
		trie.insert("Word", data);
		trie.delete("World");
		assertNull(trie.search("World"));
		assertNotNull(trie.search("Word"));
	}
	
	@Test
	public void deleteTest2() {
		Data data = new Data(5);
		trie.insert("World", data);
		trie.insert("Word", data);
		trie.insert("World", data);
		trie.delete("World");
		assertNull(trie.search("World"));
		assertNotNull(trie.search("Word"));
	}
	
	@Test
	public void deleteTest3() {
		Data data = new Data(5);
		trie.insert("Wise", data);
		trie.insert("Wishful", data);
		trie.insert("Wisdom", data);
		trie.insert("Wish", data);
		trie.delete("Wishful");
		assertNotNull(trie.search("Wish"));
		assertNotNull(trie.search("Wisdom"));
		assertNotNull(trie.search("Wise"));
		assertNull(trie.search("Wishful"));
	}
	
	@Test
	public void deleteTest4() {
		Data data = new Data(5);
		trie.insert("Precise", data);
		trie.insert("Precisely", data);
		trie.delete("Precise");
		assertNotNull(trie.search("Precisely"));
		assertNull(trie.search("Precise"));
	}
	@Test
	public void deleteTest5() {
		Data data = new Data(5);
		trie.insert("Precise", data);
		trie.insert("Precisely", data);
		trie.delete("Pre");
		assertNotNull(trie.search("Precisely"));
		assertNotNull(trie.search("Precise"));
		assertNull(trie.search("Delete"));
	}
}
